package com.aaa.sbms.controller;

import com.aaa.sbms.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * fileName:NewsController
 * description:
 * author:zz
 * createTime:2019/11/26 14:19
 * version:1.0.0
 */
@RestController
@RequestMapping("news")
public class NewsController {

    @Autowired
    private NewsService newsService;

    /**
     * 新闻列表
     * @return
     */
    @RequestMapping("list")
    public Object list(){
       /* Map map =new HashMap();
        map.put("userInfo","欢迎你"+
                ((Map)SecurityUtils.getSubject().getSession().getAttribute("userInfo")).get("REAL_NAME"));
        map.put("newsList",newsService.getList());*/
        return newsService.getList();
    }

    /**
     * 新闻分页
     * @param map
     * @return
     */
    @RequestMapping("page")
    public Object page(@RequestParam Map map){
        return newsService.getPage(map);
    }

    /**
     * 新闻附件分页
     * @param map
     * @return
     */
    @RequestMapping("newsAccPage")
    public Object newsAccPage(@RequestParam Map map){
        return newsService.newsAccPage(map);
    }

    /**
     * 查询一条新闻的数据
     * @param newsid
     * @return
     */
    @RequestMapping("newsOne")
    public Map newsOne(Integer newsid){
        return newsService.newsOne(newsid);
    }

    /**
     * 新闻类型列表
     * @return
     */
    @RequestMapping("newstypeList")
    public Object newstypeList(){
        return newsService.newstypeList();
    }

    /**
     * 一个新闻类型
     * @param newstid
     * @return
     */
    @RequestMapping("newstypeOne")
    public Object newstypeOne(Integer newstid){
        return newsService.newstypeOne(newstid);
    }

    /**
     * 一个新闻附件
     * @param accid
     * @return
     */
    @RequestMapping("newsAccOne")
    public Object newsAccOne(Integer accid){
        return newsService.newsAccOne(accid);
    }

    /**
     * 添加新闻
     * @param map
     * @return
     */
    @PostMapping("add")
    public Object add(@RequestBody Map map) {
        return newsService.add(map);
    }

    /**
     * 添加新闻类型
     * @param map
     * @return
     */
    @PostMapping("addNewstype")
    public Object addNewstype(@RequestBody Map map){
        return newsService.addNewstype(map);
    }

    /**
     * 添加新闻附件
     * @param map
     * @return
     */
    @PostMapping("addNewsAcc")
    public Object addNewsAcc(@RequestBody Map map){
        return newsService.addNewsAcc(map);
    }

    /**
     * 修改新闻
     * @param map
     * @return
     */
    @RequestMapping("update")
    public Object update(@RequestBody Map map) {
        return newsService.update(map);
    }

    /**
     * 修改新闻类型
     * @param map
     * @return
     */
    @RequestMapping("updateNewstype")
    public Object updateNewstype(@RequestBody Map map) {
        return newsService.updateNewstype(map);
    }

    /**
     * 修改新闻附件
     * @param map
     * @return
     */
    @RequestMapping("updateNewsAcc")
    public Object updateNewsAcc(@RequestBody Map map) {
        return newsService.updateNewsAcc(map);
    }

    /**
     * 根据编号删除
     * @param newsid
     * @return
     */
    @RequestMapping("delete")
    public Object delete(Integer newsid) {
        return newsService.delete(newsid);
    }

    /**
     * 根据编号删除新闻类型
     * @param newstid
     * @return
     */
    @RequestMapping("deleteNewstype")
    public Object deleteNewstype(Integer newstid) {
        return newsService.deleteNewstype(newstid);
    }

    /**
     * 根据编号删除新闻类型
     * @param accid
     * @return
     */
    @RequestMapping("deleteNewsAcc")
    public Object deleteNewsAcc(Integer accid) {
        return newsService.deleteNewsAcc(accid);
    }

    //                                                --前台--

    /**
     * 新闻列表
     * @return
     */
    @RequestMapping("front/titles")
    public Object newsList(@RequestParam Map map){
        return newsService.newsList(map);
    }

    /**
     * 查询一条新闻
     * @param newsid
     * @return
     */
    @RequestMapping("front/newsOne")
    public Object newsOne2(Integer newsid){
        return newsService.newsOne2(newsid);
    }
}
